package org.dromara.pay.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pay.domain.vo.PayActivityRegistrationVo;
import org.dromara.pay.domain.query.PayActivityRegistrationQuery;
import org.dromara.pay.domain.bo.PayActivityRegistrationBo;
import org.dromara.pay.crud.service.IPayActivityRegistrationCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * pay-活动报名
 *
 * @author yf
 * @date 2024-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/activityRegistration")
public class PayActivityRegistrationCrudController extends BaseController {

    private final IPayActivityRegistrationCrudService payActivityRegistrationService;

    /**
     * 分页查询活动报名列表
     */
    @SaCheckPermission("pay:activityRegistration:list")
    @GetMapping("/list")
    public TableDataInfo<PayActivityRegistrationVo> list(PayActivityRegistrationQuery query, PageQuery pageQuery) {
         return payActivityRegistrationService.queryPageList(query, pageQuery);
    }

    /**
     * 查询活动报名列表
     */
    @SaCheckPermission("pay:activityRegistration:list")
    @GetMapping("/allList")
    public TableDataInfo<PayActivityRegistrationVo> allList(PayActivityRegistrationQuery query) {
        List<PayActivityRegistrationVo> list =  payActivityRegistrationService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出活动报名列表
     */
    @SaCheckPermission("pay:activityRegistration:export")
    @Log(title = "活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayActivityRegistrationQuery query, HttpServletResponse response) {
        List<PayActivityRegistrationVo> list = payActivityRegistrationService.queryList(query);
        ExcelUtil.exportExcel(list, "活动报名", PayActivityRegistrationVo.class, response);
    }

    /**
     * 获取活动报名详细信息
     *
     * @param registrationId 主键
     */
    @SaCheckPermission("pay:activityRegistration:query")
    @GetMapping("/{registrationId}")
    public R<PayActivityRegistrationVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer registrationId) {
        return R.ok(payActivityRegistrationService.queryById(registrationId));
    }

    /**
     * 新增活动报名
     */
    @SaCheckPermission("pay:activityRegistration:add")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayActivityRegistrationBo bo) {
        return toAjax(payActivityRegistrationService.insertByBo(bo));
    }

    /**
     * 修改活动报名
     */
    @SaCheckPermission("pay:activityRegistration:edit")
    @Log(title = "活动报名", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayActivityRegistrationBo bo) {
        return toAjax(payActivityRegistrationService.updateByBo(bo));
    }

    /**
     * 删除活动报名
     *
     * @param registrationIds 主键串
     */
    @SaCheckPermission("pay:activityRegistration:remove")
    @Log(title = "活动报名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{registrationIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] registrationIds) {
        return toAjax(payActivityRegistrationService.deleteWithValidByIds(List.of(registrationIds), true));
    }
}
